<?php if(!defined('SPRITCH')) { exit(); }

// Spritch - An opensource PHP5 web framework

// Author: Luca Degasperi
// Licence: GNU GPL
// Site: http://www.spritch.org/

// Class: Event
// Summary: This class provides event-related functions
// Since: 0.9.1

final class event extends spritch
{
	private $events = array();
	
	public function __construct()
	{
		$app = array();
		if(file_exists(CONFIGURATION.DS.'hooks'.EXT))
		{
			include_once(CONFIGURATION.DS.'hooks'.EXT);
			$app = $hooks;
		}
		
		foreach($app as $akey => $aval)
		{
			if(array_key_exists($akey,$this->events))
				foreach($aval as $event)
					array_push($this->events[$akey],$event);
			else
				$this->events[$akey] = $aval;			
		}
		$this->profiler->log('event class started');
	}
	
	public function call($event)
	{
		if(array_key_exists($event,$this->events))
		{
			$this->profiler->log($event.' event called');
			$count = count($this->events[$event]);
			for($i = 0; $i < $count; $i++)
			{
				$e = $this->events[$event][$i];
				get($e.'.hook');
			}
		}
	}
}
?>